# Copyright 2019 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("//build_tools/bazel:build_defs.oss.bzl", "iree_compiler_cc_library", "iree_gentbl_cc_library")

package(
    default_visibility = ["//visibility:public"],
    features = ["layering_check"],
    licenses = ["notice"],  # Apache 2.0
)

iree_gentbl_cc_library(
    name = "PassesIncGen",
    tbl_outs = [
        (
            ["--gen-pass-decls"],
            "Passes.h.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "Passes.td",
    deps = ["@llvm-project//mlir:PassBaseTdFiles"],
)

iree_compiler_cc_library(
    name = "PassHeaders",
    hdrs = [
        "Passes.h",
        "Passes.h.inc",
    ],
    deps = [
        ":PassesIncGen",
        "//compiler/src/iree/compiler/Codegen/Dialect/Codegen/IR:IREECodegenDialect",
        "//compiler/src/iree/compiler/Dialect/HAL/IR",
        "//compiler/src/iree/compiler/Utils",
        "@llvm-project//mlir:LinalgTransforms",
        "@llvm-project//mlir:MemRefDialect",
        "@llvm-project//mlir:Pass",
        "@llvm-project//mlir:TransformUtils",
        "@llvm-project//mlir:Transforms",
    ],
)

iree_compiler_cc_library(
    name = "SPIRV",
    srcs = [
        "AMDConfig.cpp",
        "AdrenoConfig.cpp",
        "AppleConfig.cpp",
        "ConvertToSPIRVPass.cpp",
        "KernelConfig.cpp",
        "MaliConfig.cpp",
        "NVIDIAConfig.cpp",
        "Passes.cpp",
        "SPIRVAnnotateWinogradLoops.cpp",
        "SPIRVBreakDownLargeVector.cpp",
        "SPIRVConvertGPUTarget.cpp",
        "SPIRVEmulateI64.cpp",
        "SPIRVEraseStorageBufferStaticShape.cpp",
        "SPIRVFinalVectorLowering.cpp",
        "SPIRVInitialVectorLowering.cpp",
        "SPIRVLinkExecutables.cpp",
        "SPIRVLowerExecutableTargetPass.cpp",
        "SPIRVLowerExecutableUsingTransformDialect.cpp",
        "SPIRVMapMemRefStorageClass.cpp",
        "SPIRVMaterializeExecutableConditions.cpp",
        "SPIRVSelectLoweringStrategy.cpp",
        "SPIRVTileAndDistribute.cpp",
        "SPIRVTileAndPromote.cpp",
        "SPIRVTileAndVectorizeToCooperativeOps.cpp",
        "SPIRVTrimExecutableTargetEnv.cpp",
        "SPIRVVectorToGPUSubgroupMMAOps.cpp",
        "SPIRVVectorizeLoadStore.cpp",
        "Utils.cpp",
        "Verifiers.cpp",
    ],
    hdrs = [
        "KernelConfig.h",
        "Passes.h",
        "Utils.h",
    ],
    deps = [
        ":PassHeaders",
        ":PassesIncGen",
        "//compiler/src/iree/compiler/Codegen/Common",
        "//compiler/src/iree/compiler/Codegen/Common:TransformDialectInterpreterPass",
        "//compiler/src/iree/compiler/Codegen/Common/GPU:CommonGPUPasses",
        "//compiler/src/iree/compiler/Codegen/Common/GPU:GPUHeuristics",
        "//compiler/src/iree/compiler/Codegen/Dialect/Codegen/IR:IREECodegenDialect",
        "//compiler/src/iree/compiler/Codegen/Dialect/GPU/IR:IREEGPUDialect",
        "//compiler/src/iree/compiler/Codegen/Interfaces:PartitionableLoopsInterface",
        "//compiler/src/iree/compiler/Codegen/Transforms",
        "//compiler/src/iree/compiler/Codegen/Utils",
        "//compiler/src/iree/compiler/Dialect/Flow/IR",
        "//compiler/src/iree/compiler/Dialect/HAL/IR",
        "//compiler/src/iree/compiler/Dialect/HAL/IR:HALDialect",
        "//compiler/src/iree/compiler/Dialect/LinalgExt/IR",
        "//compiler/src/iree/compiler/Dialect/LinalgExt/Transforms",
        "//compiler/src/iree/compiler/Dialect/Util/IR",
        "//compiler/src/iree/compiler/Dialect/Util/Transforms",
        "//compiler/src/iree/compiler/Utils",
        "//llvm-external-projects/iree-dialects:IREELinalgTransformDialect",
        "//llvm-external-projects/iree-dialects:IREELinalgTransformDialectPasses",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:AffineAnalysis",
        "@llvm-project//mlir:AffineDialect",
        "@llvm-project//mlir:AffineToStandard",
        "@llvm-project//mlir:AffineUtils",
        "@llvm-project//mlir:Analysis",
        "@llvm-project//mlir:ArithDialect",
        "@llvm-project//mlir:ArithToSPIRV",
        "@llvm-project//mlir:ArithTransforms",
        "@llvm-project//mlir:ArithUtils",
        "@llvm-project//mlir:BufferizationDialect",
        "@llvm-project//mlir:ComplexToSPIRV",
        "@llvm-project//mlir:ComplexToStandard",
        "@llvm-project//mlir:ControlFlowToSPIRV",
        "@llvm-project//mlir:DialectUtils",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:FuncToSPIRV",
        "@llvm-project//mlir:FuncTransforms",
        "@llvm-project//mlir:FunctionInterfaces",
        "@llvm-project//mlir:GPUDialect",
        "@llvm-project//mlir:GPUToSPIRV",
        "@llvm-project//mlir:GPUTransforms",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:LinalgDialect",
        "@llvm-project//mlir:LinalgTransforms",
        "@llvm-project//mlir:LinalgUtils",
        "@llvm-project//mlir:MathToSPIRV",
        "@llvm-project//mlir:MathTransforms",
        "@llvm-project//mlir:MemRefDialect",
        "@llvm-project//mlir:MemRefToSPIRV",
        "@llvm-project//mlir:MemRefTransforms",
        "@llvm-project//mlir:Pass",
        "@llvm-project//mlir:SCFDialect",
        "@llvm-project//mlir:SCFToGPU",
        "@llvm-project//mlir:SCFToSPIRV",
        "@llvm-project//mlir:SCFTransforms",
        "@llvm-project//mlir:SCFUtils",
        "@llvm-project//mlir:SPIRVConversion",
        "@llvm-project//mlir:SPIRVDialect",
        "@llvm-project//mlir:SPIRVTransforms",
        "@llvm-project//mlir:SideEffectInterfaces",
        "@llvm-project//mlir:Support",
        "@llvm-project//mlir:TensorDialect",
        "@llvm-project//mlir:TensorToSPIRV",
        "@llvm-project//mlir:TensorTransforms",
        "@llvm-project//mlir:TosaDialect",
        "@llvm-project//mlir:TosaToArith",
        "@llvm-project//mlir:TransformDialect",
        "@llvm-project//mlir:TransformUtils",
        "@llvm-project//mlir:Transforms",
        "@llvm-project//mlir:VectorDialect",
        "@llvm-project//mlir:VectorInterfaces",
        "@llvm-project//mlir:VectorToGPU",
        "@llvm-project//mlir:VectorToSPIRV",
        "@llvm-project//mlir:VectorTransforms",
    ],
)
